package com.web.orderservice.clients;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.web.orderservice.entity.PageVO;
import com.web.orderservice.entity.Product;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调用商品微服务的客户端
 * FeignClient注解指定要调用服务的名称
 */
@FeignClient("product-service")
public interface ProductFeignClient {

    /**
     * 需要调用的商品接口
     * @param id
     * @return
     */
    @GetMapping("/product/{id}")
    ResponseEntity<Product> findProductById(@PathVariable Integer id);

    @GetMapping("/products")
    ResponseEntity<List<Product>> findAllProducts();

    @GetMapping("/products-page")
    ResponseEntity<PageVO> findProductsPage(
            @RequestParam(value = "current",required = false,defaultValue = "1") Integer current,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize);

    @PostMapping("/product")
    ResponseEntity<String> addProduct(@RequestBody Product product);

    @PutMapping("/product")
    ResponseEntity<String> updateProduct(@RequestBody Product product);

    @DeleteMapping("/product/{id}")
    ResponseEntity<String> deleteProduct(@PathVariable Integer id);
}
